package com.yx.crawler.template;

import java.net.URLEncoder;
import com.yx.crawler.typedef.CrawlerUrl;

public class BaiduCrawlerUrl extends CrawlerUrl {
	private String[] keywords;
	private int pageIndex;
	public BaiduCrawlerUrl(String[] keywords, int pageIndex, BaiduCrawlerListener baiduCrawlerListener) throws Exception {
		super("http://www.baidu.com/s?pn=" + (pageIndex - 1) * 10 + "&wd=" + URLEncoder.encode(searchKey(keywords), "UTF-8"),searchKey(keywords), baiduCrawlerListener);
		this.keywords = keywords;
		this.pageIndex = pageIndex;
	}

	public String[] keywords() {
		return keywords;
	}
	private static String searchKey(String[] keywords){
		String searchKeyStr="";
		if(keywords!=null&&keywords.length>0){
			searchKeyStr=keywords[0];
			for(int i=1;i<keywords.length;i++){
				searchKeyStr=searchKeyStr+" \""+keywords[i]+"\"";
			}
		}		
		return searchKeyStr;
	}

	public int pageIndex() {
		return pageIndex;
	}
}
